/*
 * @lc app=leetcode.cn id=387 lang=typescript
 *
 * [387] 字符串中的第一个唯一字符
 */

// @lc code=start
function firstUniqChar(s: string): number {
    let BadCache = new Map<string, number | null>();

    for (let index = 0; index < s.length; index++) {
        const element = s[index];
        if (BadCache.has(element)) {
            BadCache.set(element, null);
        } else {
            BadCache.set(element, index);
        }
    }
    for (const iterator of BadCache.values()) {
        if (typeof iterator === "number") return iterator;
    }
    return -1;
}
// @lc code=end
